import Vue from 'vue'
import API from '../config/api'

const proxy = '/api'

function post(api) {
	return(params = null) => Vue.http.post(
		proxy + api.url, api.params(params)
	)
}

export default {
	actions: {
		login(state, user) {
			return post(API.login)(user)
		},
		info(handler) {
			return post(API.info)()
		},
		logout(state, user) {
			localStorage.removeItem('token')
            state.token = null
			return post(API.logout)()
		}
	}
}
